<?php

namespace App\Http\Controllers\v1;

use App\Model\MessageModel;
use App\Model\SchoolModel;
use Illuminate\Http\Request;
use App\Http\Controllers\v1\BaseController;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class messageController extends BaseController
{
    //获取最新的未读消息
    public function get(Request $request){
        $token = $request->header('token');
        $uuid =  Cache::get($token)['uuid'];
        $send_id = $request->input("send_id");
        $data = DB::table('message')->where(['to_id'=>$uuid,'send_uid'=>$send_id])->groupBy('send_name')->get();
        return $this->success('最新消息',$data,200);
    }

    //获取当前会话所有信息参数用户ID和发送者ID
    public function getAll(Request $request){
        $token = $request->header('token');
        $uuid =  Cache::get($token)['uuid'];
        $send_id = $request->get('send_id');

       // $data = MessageModel::where(['to_id'=>$uuid,'send_uid'=>$send_id])->get()->toArray();
       // $mmessage = MessageModel::where(['to_id'=>$send_id,'send_uid'=>$uuid])->get()->toArray();

        $message = DB::table('message')
                    ->where(['to_id'=>$uuid,'send_uid'=>$send_id])
                    ->orWhere(['to_id'=>$send_id,'send_uid'=>$uuid])
                    ->orderBy('id')
                    ->get()->toArray();


        return $this->success('学校',$message,200);
    }

}
